/*
 * code_generator.h
 *
 *  Created on: Nov 28, 2010
 *      Author: cpy.prefers.you@gmail.com
 */

#ifndef CODE_GENERATOR_H_
#define CODE_GENERATOR_H_

#include "headers.h"

#define CODE_LEN            0x1f
#define OUTPUT_BUFFER_SIZE  0xffff
#define OUTPUT_QUEUE_SIZE   0xffff

#define GENERATE_CODE(FormattedString, ...) OutputToBuffer ? GENERATE_CODE_TO_BUFFER(FormattedString, ## __VA_ARGS__) : GENERATE_CODE_TO_QUEUE(FormattedString, ## __VA_ARGS__)
#define GENERATE_CODE_TO_BUFFER(FormattedString, ...) sprintf(OutputBuffer[OutputBufferLen++], FormattedString, ## __VA_ARGS__)
#define GENERATE_CODE_TO_QUEUE(FormattedString, ...) sprintf(OutputQueue[OutputQueueLen++], FormattedString, ## __VA_ARGS__)

extern int OutputToBuffer;
extern int OutputBufferLen;
extern int OutputQueueLen;
extern char OutputBuffer[OUTPUT_BUFFER_SIZE][CODE_LEN];
extern char OutputQueue[OUTPUT_QUEUE_SIZE][CODE_LEN];
extern int LabelCount;

extern int FlushOutputBufferToQueue();
extern int FlushOutputQueueToStream();
char *NewLabel(int *LabelCount);

#endif /* CODE_GENERATOR_H_ */
